var app = angular.module('zhijiaoAdminApp.controllers');

app.controller('projectCtr', ['$rootScope', '$scope', 'ajaxService', 'layerService', 'toastPCService', '$timeout', 'tempDataService', 'session',
    function ($rootScope, $scope, ajax, layer, toast, timeout, temp, session) {
        var edit = function () {
            return {id: '', title: '', start_date: '', end_date: '', length: '', structure: '', cad: '', file_xlsx: ''};
        };

        $scope.data = {
            list: [],
            edit: edit(),
            tabList: [
                {name: 'G212桥梁', index: 1},
                {name: '桥梁模型', index: 2},
            ], index: 1,
            uploading: false,
        };
        $scope.$on('$stateChangeSuccess', function () {
            ajax('projectIndex', {}, function (rel) {
                if (!rel.code) {
                    $scope.data.list = rel.data;
                    $scope.edit(1)
                }
            })
        })


        $scope.edit = function (index) {
            $scope.data.index = index;
            $scope.data.edit = edit();
            $scope.data.list.forEach(item => {
                if (item.id == index) {
                    $scope.data.edit = item;
                }
            })
        }

        $scope.commit = function () {
            if ($('#editForm').valid()) {
                ajax('projectSave', $scope.data.edit, function (rel) {
                    if (!rel.code) {
                        toast.show(1, '保存成功');
                        $scope.getList();
                        $('#myModal').modal('hide');
                    }
                })
            }
        }


    }
])

app.controller('diseaseCtr', ['$rootScope', '$scope', 'ajaxService', 'layerService', 'toastPCService', '$timeout', 'tempDataService', 'session',
    function ($rootScope, $scope, ajax) {

        $scope.data = {
            list: [],
            tabList: [
            ], index: 0,
        };
        $scope.$on('$stateChangeSuccess', function () {
            $scope.getDisease(1)
            //生成10个点位
            for (var i = 1; i < 9; i++) {
                $scope.data.tabList.push({name: '点位' + i, index: i});
            }
        })
        $scope.getDisease = function (position) {
            if(position == $scope.data.index) return;
            $scope.data.index = position;
            ajax('disease', {position: position}, function (rel) {
                if (!rel.code) {
                    $scope.data.list = rel.data;
                }
            })
        }

    }
])